{
  LW Dyna -- LightWave DynaTypes

  This unit defines the types and macros for simple DynaTypes.

  Based on lwdyna.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit LW_Dyna;

{$mode objfpc}{$H+}

interface

uses
  LW_Monitor,
  LW_XPanel ;

const
  {
    DynaType codes.
  }
  DY_NULL        =  0;
  DY_STRING      =  1;
  DY_INTEGER     =  2;
  DY_FLOAT       =  3;
  DY_DISTANCE    =  4;
  DY_VINT        =  5;
  DY_VFLOAT      =  6;
  DY_VDIST       =  7;
  DY_BOOLEAN     =  8;
  DY_CHOICE      =  9;
  DY_SURFACE     = 10;
  DY_FONT        = 11;
  DY_TEXT        = 12;
  DY_LAYERS      = 13;
  DY_CUSTOM      = 14;
  DY_RANGE       = 15;
  DY_LWITEM      = 16;
  DY_PERCENT     = 17;
  DY_POPUP       = 18;
  DY_AREA        = 19;
  DY_XPANEL      = 20;
  DY_TREE        = 21;
  DY_MLIST       = 22;
  DY_POINTER     = 23;
  DY__LAST       = DY_POINTER;

  {
    DynaType and DynaValue error codes.
  }
  DYERR_NONE        =  0;
  DYERR_MEMORY      = -1;
  DYERR_BADTYPE     = -2;
  DYERR_BADSEQ      = -3;
  DYERR_BADCTRLID   = -4;
  DYERR_TOOMANYCTRL = -5;
  DYERR_INTERNAL    = -6;

  LWDYNACONVERTFUNC_GLOBAL  = 'LWM: Dynamic Conversion';
  LWDYNAREQFUNCS_GLOBAL     = 'LWM: Dynamic Request 2' ;
  LWDYNAMONITORFUNCS_GLOBAL = 'LWM: Dynamic Monitor'   ;

  dtString  = 0;
  dtInteger = 1;
  dtFloat   = 2;
  dtIVector = 3;
  dtFVector = 4;
  dtPointer = 5;
  dtCustom  = 6;

type
  TDynaType = Integer;

  {
    DynaValue union.
  }
  PDyValString = ^TDyValString;
  TDyValString = record
    Type_  : TDynaType;
    Buf    : PChar    ;
    BufLen : Integer  ;
  end;

  PDyValInt = ^TDyValInt;
  TDyValInt = record
    Type_  : TDynaType;
    Value  : Integer  ;
    DefVal : Integer  ;
  end;

  PDyValFloat = ^TDyValFloat;
  TDyValFloat = record
    type_  : TDynaType;
    Value  : Double   ;
    DefVal : Double   ;
  end;

  PDyValIVector = ^TDyValIVector;
  TDyValIVector = record
    Type_  : TDynaType              ;
    Val    : array [0..2] of Integer;
    DefVal : Integer                ;
  end;

  PDyValFVector = ^TDyValFVector;
  TDyValFVector = record
    Type_  : TDynaType             ;
    Val    : array [0..2] of Double;
    DefVal : Double                ;
  end;

  PDyValCustom = ^TDyValCustom;
  TDyValCustom = record
    Type_  : TDynaType              ;
    Val    : array [0..3] of SizeInt;
  end;

  PDyValPointer = ^TDyValPointer;
  TDyValPointer = record
    Type_ : TDynaType;
    Ptr   : Pointer  ;
  end;

  PDynaValue = ^TDynaValue;
  TDynaValue = record
    case Integer of
      0 : (Type_ : TDynaType    );
      1 : (Str   : TDyValString );
      2 : (IntV  : TDyValInt    );
      3 : (Flt   : TDyValFloat  );
      4 : (IVec  : TDyValIVector);
      5 : (FVec  : TDyValFVector);
      6 : (Ptr   : TDyValPointer);
      7 : (Cust  : TDyValCustom );
  end;

  TDynaValueRec = record
    case dType : TDynaType of
      dtString  : (dString  : PChar                  );
      dtInteger : (dInteger : Integer                );
      dtFloat   : (dFloat   : Double                 );
      dtIVector : (dIVector : array [0..2] of Integer);
      dtFVector : (dFVector : array [0..2] of Double );
      dtPointer : (dPointer : Pointer                );
      dtCustom  : (dCustom  : array [0..3] of SizeInt);
  end;

  {
    Conversion hints.
  }
  PDyChoiceHint = ^TDyChoiceHint;
  TDyChoiceHint = record
    Item  : PChar  ;
    Value : Integer;
  end;

  PDyBitfieldHint = ^TDyBitfieldHint;
  TDyBitfieldHint = record
    Code   : Char   ;
    BitVal : Integer;
  end;

  PDynaStringHint = ^TDynaStringHint;
  TDynaStringHint = record
    Chc  : PDyChoiceHint  ;
    Bits : PDyBitfieldHint;
  end;

  {
    Dynamic Requester types.
  }
  PDynaRequest = ^TDynaRequest;
  TDynaRequest = record end;

  PDyReqStringDesc = ^TDyReqStringDesc;
  TDyReqStringDesc = record
    Type_ : TDynaType;
    Width : Integer  ;
  end;

  PDyReqChoiceDesc = ^TDyReqChoiceDesc;
  TDyReqChoiceDesc = record
    Type_    : TDynaType;
    Items    : PPChar   ;
    Vertical : Integer  ;
  end;

  PDyReqTextDesc = ^TDyReqTextDesc;
  TDyReqTextDesc = record
    Type_ : TDynaType;
    Text  : PPChar   ;
  end;

  PDyReqControlDesc = ^TDyReqControlDesc;
  TDyReqControlDesc = record
    case Integer of
      0 : (Type_   : TDynaType       );
      1 : (String_ : TDyReqStringDesc);
      2 : (Choice  : TDyReqChoiceDesc);
      3 : (Text    : TDyReqTextDesc  );
  end;

  {
    DynaValue conversion global service.
  }
  PTDynaConvertFunc = ^TDynaConvertFunc ;
  TDynaConvertFunc = function
                     (const From : PDynaValue     ;
                            To_  : PDynaValue     ;
                      const Hint : PDynaStringHint) : Integer;

  {
    Dynamic requester service.
  }
  PDynaReqFuncs = ^TDynaReqFuncs;
  TDynaReqFuncs = record
    Create   : function
               (const Title      : PChar            ) : PDynaRequest;
    AddCtrl  : function
               (      Req        : PDynaRequest     ;
                const Label_     : PChar            ;
                      Descriptor : PDyReqControlDesc) : Integer     ;
    CtrlType : function
               (      Req        : PDynaRequest     ;
                      Ctl        : Integer          ) : TDynaType   ;
    ValueSet : function
               (      Req        : PDynaRequest     ;
                      Ctl        : Integer          ;
                      Value      : PDynaValue       ) : Integer     ;
    ValueGet : function
               (      Req        : PDynaRequest     ;
                      Ctl        : Integer          ;
                      Value      : PDynaValue       ) : Integer     ;
    Post     : function
               (      Req        : PDynaRequest     ) : Integer     ;
    Destroy  : procedure
               (      Req        : PDynaRequest     ) ;
    XPanel   : function
               (      Req        : PDynaRequest     ) : PLWXPanel   ;
  end;

  {
    Global monitor.
  }
  PDynaMonitorFuncs = ^TDynaMonitorFuncs;
  TDynaMonitorFuncs = record
    Create  : function
             (const Title   : PChar     ;
              const Caption : PChar     ) : PLWMonitor;
    Destroy : procedure
             (      Mon     : PLWMonitor) ;
  end;

implementation

end.

